package com.ruoyi.eam.controller;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import java.util.Random;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.eam.doman.EamManageD;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.eam.doman.EamManageH;
import com.ruoyi.eam.service.IEamManageHService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

import static com.ruoyi.eam.config.EnumType.ly;

/**
 * 资产记录2Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/eam")
public class EamManageHController extends BaseController
{
    @Autowired
    private IEamManageHService eamManageHService;

    /**
     * 查询资产记录2列表
     */
//    @RequiresPermissions("eam-a:eam:list")
    @GetMapping("/list")
    public TableDataInfo list(EamManageH eamManageH)
    {
        startPage();
        List<EamManageH> list = eamManageHService.selectEamManageHList(eamManageH);
        System.out.println(list.size());
        return getDataTable(list);
    }

    /**
     * 导出资产记录2列表
     */
    //@RequiresPermissions("eam-a:eam:export")
    @Log(title = "资产记录2", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamManageH eamManageH)
    {
        List<EamManageH> list = eamManageHService.selectEamManageHList(eamManageH);
        ExcelUtil<EamManageH> util = new ExcelUtil<EamManageH>(EamManageH.class);
        util.exportExcel(response, list, "资产记录2数据");
    }

    /**
     * 获取资产记录2详细信息
     */
    //@RequiresPermissions("eam-a:eam:query")
    @GetMapping(value = "/{manageId}")
    public AjaxResult getInfo(@PathVariable("manageId") Long manageId)
    {
        return success(eamManageHService.selectEamManageHByManageId(manageId));
    }

    /**
     * 新增资产记录2
     */
//    @RequiresPermissions("eam-a:eam:add")
//    @Log(title = "资产记录2", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamManageH eamManageH)
    {
        eamManageH.setAssetCode(eamManageH.getAssetCode());
        eamManageH.setPreparedDate(eamManageH.getClaimingDate());
        eamManageH.setCreateTime(eamManageH.getClaimingDate());


        return toAjax(eamManageHService.insertEamManageH(eamManageH));
    }

    /**
     * 修改资产记录2
     */
    //@RequiresPermissions("eam-a:eam:edit")
    @Log(title = "资产记录2", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamManageH eamManageH)
    {
        return toAjax(eamManageHService.updateEamManageH(eamManageH));
    }

    /**
     * 删除资产记录2
     */
    //@RequiresPermissions("eam-a:eam:remove")
    @Log(title = "资产记录2", businessType = BusinessType.DELETE)
	@DeleteMapping("/{manageIds}")
    public AjaxResult remove(@PathVariable Long[] manageIds)
    {
        return toAjax(eamManageHService.deleteEamManageHByManageIds(manageIds));
    }

    @GetMapping("/getCode")
    public  AjaxResult generateEncodedString() {
        // 获取当前时间戳
        Random random = new Random();
        // 生成一个16位的随机整数
        long randomNumber = (long) (random.nextDouble() * 9000000000000000L) + 1000000000000000L;
        // 返回编码后的字符串
        return AjaxResult.success("LYD"+randomNumber);
    }




    @GetMapping(value = "/DelUpd/{manageIds}")
    public AjaxResult updateDelEamH(@PathVariable String[] manageIds){
        return success(eamManageHService.updateDelEamH(manageIds));
    }

}
